package hoja1;

/* Universidad del Valle de Guatemala
 * Boris Becerra
 * Sara López
 * Matías Vásquez
 * Sección: 20
 */

//Se importa la clase del paquete


import java.math.BigDecimal;


public class RCarro implements Radio{
    private boolean estado = true;
    private int AMFM = 0;
    private int AM = 530;
    private float FM = (float) 87.9;
    
    float var1 = 0;
    float var2 = 0;
    float var3 = 0;
    float var4 = 0;
    float var5 = 0;
    float var6 = 0;
    float var7 = 0;
    float var8 = 0;
    float var9 = 0;
    float var10 = 0;
    float var11 = 0;
    float var12 = 0;
    
    boolean varFM1 = true;
    boolean varFM2 = true;
    boolean varFM3 = true;
    boolean varFM4 = true;
    boolean varFM5 = true;
    boolean varFM6 = true;
    boolean varFM7 = true;
    boolean varFM8 = true;
    boolean varFM9 = true;
    boolean varFM10 = true;
    boolean varFM11 = true;
    boolean varFM12 = true;
    
    
    /**
     *
     * @return
     */
    @Override
    public boolean getEstado()
    {
        
        return estado;
    }

    @Override
    public void setEstado(boolean estado)
    {
        this.estado = estado; 
    }

    @Override
    public int getAMFM()
    {
        return AMFM;
    }

    @Override
    public void setAMFM(int amfm)
    {
        this.AMFM = amfm;
    }

    @Override
    public void sintonizar(boolean sintonizacion)
    {
        if(sintonizacion == true)
        {
            if(getAMFM() == 1)
            {
                FM += 0.2;
                if(FM > 107.9)
                {
                    FM = (float) 87.9;
                }
            }else
            {
                AM += 10;
                if(AM > 1610)
                {
                    AM = 530;
                }
            }
        }else
        {
            if(getAMFM() == 1)
            {
                FM -= 0.2;
                if(FM < 87.9)
                {
                    FM = (float) 107.9;
                }
            }else
            {
                AM -= 10;
                if(AM < 530)
                {
                    AM = 1610;
                }
            }
        }
    }

    @Override
    public void guardar(int numguardar)
    {
        switch (numguardar){
                case 1:
                    var1 = getEmisora();
                    if(getAMFM() == 1)
                    {
                        varFM1 = true;
                    }else{
                        varFM1 = false;
                    }
                    break;
                case 2:
                    var2 = getEmisora();
                    if(getAMFM() == 1)
                    {
                        varFM2 = true;
                    }else{
                        varFM2 = false;
                    }
                    break;
                case 3:
                    var3 = getEmisora();
                    if(getAMFM() == 1)
                    {
                        varFM3 = true;
                    }else{
                        varFM3 = false;
                    }
                    break;
                case 4:
                    var4 = getEmisora();
                    if(getAMFM() == 1)
                    {
                        varFM4 = true;
                    }else{
                        varFM4 = false;
                    }
                    break;
                case 5:
                    if(getAMFM() == 1)
                    {
                        varFM5 = true;
                    }else{
                        varFM5 = false;
                    }
                    var5 = getEmisora();
                    break;
                case 6:
                    if(getAMFM() == 1)
                    {
                        varFM6 = true;
                    }else{
                        varFM6 = false;
                    }
                    var6 = getEmisora();
                    break;
                case 7:
                    if(getAMFM() == 1)
                    {
                        varFM7 = true;
                    }else{
                        varFM7 = false;
                    }
                    var7 = getEmisora();
                    break;
                case 8:
                    if(getAMFM() == 1)
                    {
                        varFM8 = true;
                    }else{
                        varFM8 = false;
                    }
                    var8 = getEmisora();
                    break;
                case 9:
                    if(getAMFM() == 1)
                    {
                        varFM9 = true;
                    }else{
                        varFM9 = false;
                    }
                    var9 = getEmisora();
                    break;
                case 10:
                    if(getAMFM() == 1)
                    {
                        varFM10 = true;
                    }else{
                        varFM10 = false;
                    }
                    var10 = getEmisora();
                    break;
                case 11:
                    if(getAMFM() == 1)
                    {
                        varFM11 = true;
                    }else{
                        varFM11 = false;
                    }
                    var11 = getEmisora();
                    break;
                case 12:
                    if(getAMFM() == 1)
                    {
                        varFM12 = true;
                    }else{
                        varFM12 = false;
                    }
                    var12 = getEmisora();
                    break;
        }
    }

    @Override
    public void memoria(int nummemoria)
    {
        
            switch (nummemoria){
                    case 1:
                        if(varFM1 == true)
                        {
                            FM = var1;
                            setAMFM(1);
                        }else{
                            AM = (int) var1;
                            setAMFM(0);
                        }
                        break;
                    case 2:
                        if(varFM2 == true)
                        {
                            FM = var2;
                            setAMFM(1);
                        }else{
                            AM = (int) var2;
                            setAMFM(0);
                        }
                        break;
                    case 3:
                        if(varFM3 == true)
                        {
                            FM = var3;
                            setAMFM(1);
                        }else{
                            AM = (int) var3;
                            setAMFM(0);
                        }
                        break;
                    case 4:
                        if(varFM4 == true)
                        {
                            FM = var4;
                            setAMFM(1);
                        }else{
                            AM = (int) var4;
                            setAMFM(0);
                        }
                        break;
                    case 5:
                        if(varFM5 == true)
                        {
                            FM = var5;
                            setAMFM(1);
                        }else{
                            AM = (int) var5;
                            setAMFM(0);
                        }
                        break;
                    case 6:
                        if(varFM6 == true)
                        {
                            FM = var6;
                            setAMFM(1);
                        }else{
                            AM = (int) var6;
                            setAMFM(0);
                        }
                        break;
                    case 7:
                        if(varFM7 == true)
                        {
                            FM = var7;
                            setAMFM(1);
                        }else{
                            AM = (int) var7;
                            setAMFM(0);
                        }
                        break;
                    case 8:
                        if(varFM8 == true)
                        {
                            FM = var8;
                            setAMFM(1);
                        }else{
                            AM = (int) var8;
                            setAMFM(0);
                        }
                        break;
                    case 9:
                        if(varFM9 == true)
                        {
                            FM = var9;
                            setAMFM(1);
                        }else{
                            AM = (int) var9;
                            setAMFM(0);
                        }
                        break;
                    case 10:
                        if(varFM10 == true)
                        {
                            FM = var10;
                            setAMFM(1);
                        }else{
                            AM = (int) var10;
                            setAMFM(0);
                        }
                        break;
                    case 11:
                        if(varFM11 == true)
                        {
                            FM = var11;
                            setAMFM(1);
                        }else{
                            AM = (int) var11;
                            setAMFM(0);
                        }
                        break;
                    case 12:
                        if(varFM12 == true)
                        {
                            FM = var12;
                            setAMFM(1);
                        }else{
                            AM = (int) var12;
                            setAMFM(0);
                        }
                        break;
            
        
        }
    }

    @Override
    public float getEmisora()
    {
        int decimalPlaces = 2;
        BigDecimal bd = new BigDecimal(FM);
        bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
        FM = (float) bd.doubleValue();
        if(getAMFM() == 1)
        {
            return FM;
        }else{
            return AM;
        }
    }
}